//
//  MoreTableViewController.m
//  YiQiTingShu
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//

#import "MoreTableViewController.h"
#import "PublicHeader.h"
#import <MJExtension.h>
#import "FHeardModel.h"
#import "WHNTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "WWListenListViewController.h"

#define URLString @"http://mobile.ximalaya.com/m/subject_list?device=iPhone&page=1&per_page=20&position=1&scale=2&title=%E7%8C%9C%E4%BD%A0%E5%96%9C%E6%AC%A2"

@interface MoreTableViewController ()
@property(nonatomic, strong)NSMutableArray *dataSource;
@end
static NSString *identifier = @"identifier";
@implementation MoreTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataSource = [NSMutableArray array];
    [self initData];
    [self.tableView registerClass:[WHNTableViewCell class] forCellReuseIdentifier:identifier];
    self.tableView.tableHeaderView = [[UIView alloc] init];
    [self.view NightWithType:UIViewColorTypeNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initData
{
    [AFTools getDataByURLString:URLString WithDataBlock:^(id data) {
        [_dataSource addObjectsFromArray:[FHeardModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]]];
        [self.tableView reloadData];
    }];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WHNTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    FHeardModel *model = _dataSource[indexPath.row];
    cell.kind = WHNTableViewCellKindThree;
    [cell.MainImageView sd_setImageWithURL:[NSURL URLWithString:model.coverPathSmall]];
    cell.NameLabel.text = model.title;
    cell.CountLabel.text = model.footnote;
    cell.IconImageView.image = [UIImage imageNamed:@"f_jptd"];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WWListenListViewController *vc = [[WWListenListViewController alloc] init];
    FHeardModel *model = _dataSource[indexPath.row];
    vc.specialId = [[model specialId] integerValue];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
